package com.funtl.spring.cloud.alibaba.consumer.controller;

import com.funtl.spring.cloud.alibaba.consumer.service.ConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RefreshScope
public class ConsumerController {

    private final RestTemplate restTemplate;

    @Autowired
    public ConsumerController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }
    @RequestMapping("/echo/consumer/{st}")
    public String echo(@PathVariable("st") String st){
        return restTemplate.getForObject("http://service-provider/echo/provider/"+st,String.class);
    }

    /**
     * 通过Feign来调用provider提供的fn服务
     */
    @Autowired
    private ConsumerService feignService;
    @RequestMapping("/consumer/fn")
    public String fn(){
        return feignService.fn();
    }


    /**
     * 演示nacos config 分布式配置中心
     *
     * @RefreshScope 动态刷新配置
     */

    @Value("${love}")
    private String love;

    @RequestMapping("/nacos/config/love")
    public String get(){
        return love;
    }

}
